package com.shujia.wyh.day11;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
    HashMap<Student,String>

    唯一性是针对于key来说的，如果在重写了hashCode()方法和equals()的同时，将Student类型作为value值存在，是不会去重
 */
public class MapTest1 {
    public static void main(String[] args) {
        //1、创建集合对象
        HashMap<Student, String> map = new HashMap<>();

        //2、创建元素对象
        Student s1 = new Student("吴涛", 18);
        Student s2 = new Student("陈涛", 17);
        Student s3 = new Student("王硕", 20);
        Student s4 = new Student("小虎", 19);
        Student s5 = new Student("吴涛", 18);

        //3、添加元素到集合
        map.put(s1, "小虎");
        map.put(s2, "笑哥");
        map.put(s3, "刘亦菲");
        map.put(s4, "冯提莫");
        map.put(s5, "童哥");

        Set<Map.Entry<Student, String>> set = map.entrySet();
        for (Map.Entry<Student, String> entry : set) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "---" + value);
        }
    }
}
